gpio: support gpio set/get pull status
authorCaesar Wang <[email protected]>
Wed, 25 May 2016 10:48:45 +0000 (18:48 +0800)
committerCaesar Wang <[email protected]>
Fri, 27 May 2016 01:39:56 +0000 (09:39 +0800)
On some platform gpio can set/get pull status when input, add these
function so we can set/get gpio pull status when need it. And they are
optional function.

drivers/gpio/gpio.c
include/drivers/gpio.h

index c06172fc5ba80652363f3006c25488035f5a8fd1..ef6bb9c820e85330f1408214f02de810b95db7f3 100644 (file)
@@ -80,6 +80,26 @@ void gpio_set_value(int gpio, int value)
        ops->set_value(gpio, value);
 }
 
+void gpio_set_pull(int gpio, int pull)
+{
+       assert(ops);
+       assert(ops->set_pull != 0);
+       assert((pull == GPIO_PULL_NONE) || (pull == GPIO_PULL_UP) ||
+              (pull == GPIO_PULL_DOWN));
+       assert(gpio >= 0);
+
+       ops->set_pull(gpio, pull);
+}
+
+int gpio_get_pull(int gpio)
+{
+       assert(ops);
+       assert(ops->get_pull != 0);
+       assert(gpio >= 0);
+
+       return ops->get_pull(gpio);
+}
+
 /*
  * Initialize the gpio. The fields in the provided gpio
  * ops pointer must be valid.
index a5cb5c7f7b91fdbed5b43232f8d78cb0c5e64eb2..633b3f6b09d7980e7455c6c5387e626a8449d037 100644 (file)
 #define GPIO_LEVEL_LOW         0
 #define GPIO_LEVEL_HIGH                1
 
+#define GPIO_PULL_NONE         0
+#define GPIO_PULL_UP           1
+#define GPIO_PULL_DOWN         2
+
 typedef struct gpio_ops {
        int (*get_direction)(int gpio);
        void (*set_direction)(int gpio, int direction);
        int (*get_value)(int gpio);
        void (*set_value)(int gpio, int value);
+       void (*set_pull)(int gpio, int pull);
+       int (*get_pull)(int gpio);
 } gpio_ops_t;
 
 int gpio_get_direction(int gpio);
 void gpio_set_direction(int gpio, int direction);
 int gpio_get_value(int gpio);
 void gpio_set_value(int gpio, int value);
+void gpio_set_pull(int gpio, int pull);
+int gpio_get_pull(int gpio);
 void gpio_init(const gpio_ops_t *ops);
 
 #endif /* __GPIO_H__ */